//
//  ArroundFirstTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-12-7.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//  顶部的cell

#import "ArroundFirstTableViewCell.h"
#import "Grouble.h"
#import "JFMenuBtnView.h"


@implementation ArroundFirstTableViewCell
+ (instancetype)ArroundFirstTableViewCell:(UITableView *)tableView imgWithTitle :(NSArray *)imgWithTitle
{
    static NSString *ID = @"arroundfirsttablecell";
    ArroundFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ArroundFirstTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID imgWithTitle:imgWithTitle];
    }
    // 设置不能选中,选中每反应
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier imgWithTitle :(NSArray *)menuArray
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView * topView = [[UIView alloc]init];
        topView.frame = CGRectMake(0, 0, ScreenWidth, 160);
        topView.userInteractionEnabled = YES;
        topView.backgroundColor = [UIColor whiteColor];
        [self addSubview:topView];

        //创建8个
        for (int i = 0; i < 8; i++) {
            if (i < 4) {
                CGRect frame = CGRectMake(i*ScreenWidth/4, 0, ScreenWidth/4, 80);
                NSString *title = [menuArray[i] objectForKey:@"title"];
                NSString *imageStr = [menuArray[i] objectForKey:@"image"];
                JFMenuBtnView *btnView = [[JFMenuBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
                btnView.tag = 20+i;
                [topView addSubview:btnView];
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
                [btnView addGestureRecognizer:tap];
                
            }else if(i<8){
                CGRect frame = CGRectMake((i-4)*ScreenWidth/4, 80, ScreenWidth/4, 80);
                NSString *title = [menuArray[i] objectForKey:@"title"];
                NSString *imageStr = [menuArray[i] objectForKey:@"image"];
                JFMenuBtnView *btnView = [[JFMenuBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
                btnView.tag = 20+i;
                [topView addSubview:btnView];
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
                [btnView addGestureRecognizer:tap];
            }
        }
        
        for (int i = 0; i < 2; i++) {
            //背景  这个可以进行重构。不要一行一行创建
            UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(i*ScreenWidth/2, 162, ScreenWidth/2, 80)];
            if (i<2) {
                backView.frame = CGRectMake(i*ScreenWidth/2, 162, ScreenWidth/2, 80);
            }else{
                backView.frame = CGRectMake((i-2)*ScreenWidth/2, 80 + 162, ScreenWidth/2, 80);
            }
            backView.tag = 100+i;
            // 设置边框的宽度
            backView.layer.borderWidth = 0.25;
            //  backView.layer.borderColor = [separaterColor CGColor];
            // 设置边框的颜色
            backView.layer.borderColor = [ZCJColor(200, 199, 204)  CGColor];
            
            
            //点击事件
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBackView:)];
            [backView addGestureRecognizer:tap];
            
            //标题
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, ScreenWidth/2-10-60, 30)];
            titleLabel.text = @"庐山特产";
            titleLabel.tag = 200+i;
            titleLabel.font = [UIFont boldSystemFontOfSize:17];
            [backView addSubview:titleLabel];
            
            //子标题
            UILabel *subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, ScreenWidth/2-10-60, 30)];
            subTitleLabel.tag = 220+i;
            subTitleLabel.font = [UIFont systemFontOfSize:12];
            subTitleLabel.text = @"庐山茶饼";
            [backView addSubview:subTitleLabel];
            
            //图
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2-10-60, 10, 60, 60)];
            imageView.tag = 240+i;
            [imageView setImage:[UIImage imageNamed:@"chabing"]];
            imageView.layer.masksToBounds = YES;
            imageView.layer.cornerRadius = 30;
            [backView addSubview:imageView];
            
            [self addSubview:backView];
            
        }

        // Initialization code
    }
    return self;
}
- (void)OnTapBtnView:(UITapGestureRecognizer *)gester
{
    ZCJLog(@"ldjfdlflj");
}
- (void)OnTapBackView:(UITapGestureRecognizer *)gester
{
    ZCJLog(@"OnTapBackView");
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
